package com.example.demo.order.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.demo.order.entity.OOrderComment;
import com.example.demo.order.service.OOrderCommentService;
import com.example.demo.util.result.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 订单评论表; 前端控制器
 * </p>
 *
 * @author 涛
 * @since 2024-08-01
 */
@RestController
@RequestMapping("/oOrderComment")
@Tag(name = "oOrderComment", description = "订单评论表")
public class OOrderCommentController {
    @Autowired
    private OOrderCommentService oOrderCommentService;

    /**
     * 获取订单评论列表
     */
    @GetMapping("/getCommentList")
    @Operation(summary = "获取订单评论列表", description = "获取订单评论列表")
    public Result<?> getCommentList(@RequestParam(value = "current", required = false, defaultValue = "1")Integer current,
                                    @RequestParam(value = "size", required = false, defaultValue = "10")Integer size,
                                    OOrderComment comment){
        Page<OOrderComment> page = new Page<>(current,size);
        QueryWrapper<OOrderComment> queryWrapper = new QueryWrapper<>(comment);
        return Result.ok(oOrderCommentService.page(page,queryWrapper));
    }

    /**
     * 根据ID查询订单评论信息
     */
    @GetMapping("/getCommentById")
    @Operation(summary = "根据ID查询订单评论信息", description = "根据ID查询订单评论信息")
    public Result<?> getCommentById(Integer id){
        return Result.ok(oOrderCommentService.getById(id));
    }

    /**
     * 修改订单评论信息
     */
    @PutMapping("/updateComment")
    @Operation(summary = "根据id修改订单评论信息", description = "根据id修改订单评论信息")
    @Transactional
    public Result<?> updateComment(@RequestBody OOrderComment comment){
        return Result.ok(oOrderCommentService.updateById(comment));
    }

    /**
     * 新增订单评论信息
     */
    @PostMapping("/addComment")
    @Operation(summary = "新增订单评论信息", description = "新增订单评论信息")
    public Result<?> addComment(@RequestBody OOrderComment comment){
        return Result.ok(oOrderCommentService.save(comment));
    }

    /**
     * 删除订单评论
     */
    @DeleteMapping("/deleteCommentById")
    @Operation(summary = "删除订单评论", description = "删除订单评论")
    @Transactional
    public Result<?> deleteCommentById(Integer id){
        return Result.ok(oOrderCommentService.removeById(id));
    }
}

